﻿#include "PolarCoordinateSettingData.h"

namespace pst
{
    PolarCoordinateSettingData::PolarCoordinateSettingData(QObject* parent)
        : QObject(parent)
        , m_angleAxisDisplay(new Style2D_Axis)
        , m_angleAxisRange(new Style2D_AxisRange)
        , m_radiusAxisDisplay(new Style2D_Axis)
        , m_radiusAxisRange(new Style2D_AxisRange)
        , m_grid(new Style2D_GridLine)
        , m_title(new Style2D_Title)
        , m_legend(new Style2D_Legend)
        //, m_dataProperty(new Style2D_DataProperty)
    {
        m_angleAxisDisplay->m_valuePrecision = 2;
    }

    PolarCoordinateSettingData::~PolarCoordinateSettingData()
    {
        //if (m_angleAxisDisplay)
        //{
        //    delete m_angleAxisDisplay;
        //    m_angleAxisDisplay = nullptr;
        //}
        //if (m_angleAxisRange)
        //{
        //    delete m_angleAxisRange;
        //    m_angleAxisRange = nullptr;
        //}
        //if (m_radiusAxisDisplay)
        //{
        //    delete m_radiusAxisDisplay;
        //    m_radiusAxisDisplay = nullptr;
        //}
        //if (m_radiusAxisRange)
        //{
        //    delete m_radiusAxisRange;
        //    m_radiusAxisRange = nullptr;
        //}
        //if (m_grid)
        //{
        //    delete m_grid;
        //    m_grid = nullptr;
        //}
        //if (m_title)
        //{
        //    delete m_title;
        //    m_title = nullptr;
        //}
        //if (m_legend)
        //{
        //    delete m_legend;
        //    m_legend = nullptr;
        //}
        //if (m_dataProperty)
        //{
        //    delete m_dataProperty;
        //    m_dataProperty = nullptr;
        //}
    }

    void PolarCoordinateSettingData::copyData(const PolarCoordinateSettingData* data)
    {
        if (this == data || data == nullptr) return;
        this->m_angleAxisDisplay->copyData(data->m_angleAxisDisplay);
        this->m_angleAxisRange->copyData(data->m_angleAxisRange);
        this->m_radiusAxisDisplay->copyData(data->m_radiusAxisDisplay);
        this->m_radiusAxisRange->copyData(data->m_radiusAxisRange);
        this->m_grid->copyData(data->m_grid);
        this->m_title->copyData(data->m_title);
        this->m_legend->copyData(data->m_legend);
        //this->m_dataProperty->copyData(data->m_dataProperty);
    }

    void PolarCoordinateSettingData::setAngleAxisDisplay(Style2D_Axis* data)
    {
        m_angleAxisDisplay = data;
    }

    Style2D_Axis* PolarCoordinateSettingData::getAngleAxisDisplay() const
    {
        return m_angleAxisDisplay;
    }

    void PolarCoordinateSettingData::setAngleAxisRange(Style2D_AxisRange* data)
    {
        m_angleAxisRange = data;
    }

    Style2D_AxisRange* PolarCoordinateSettingData::getAngleAxisRange() const
    {
        return m_angleAxisRange;
    }

    void PolarCoordinateSettingData::setRadiusAxisDisplay(Style2D_Axis* data)
    {
        m_radiusAxisDisplay = data;
    }

    Style2D_Axis* PolarCoordinateSettingData::getRadiusAxisDisplay() const
    {
        return m_radiusAxisDisplay;
    }

    void PolarCoordinateSettingData::setRadiusAxisRange(Style2D_AxisRange* data)
    {
        m_radiusAxisRange = data;
    }

    Style2D_AxisRange* PolarCoordinateSettingData::getRadiusAxisRange() const
    {
        return m_radiusAxisRange;
    }

    void PolarCoordinateSettingData::setGrid(Style2D_GridLine* data)
    {
        m_grid = data;
    }
    Style2D_GridLine* PolarCoordinateSettingData::getGrid() const
    {
        return m_grid;
    }

    void PolarCoordinateSettingData::setTitle(Style2D_Title* data)
    {
        m_title = data;
    }

    Style2D_Title* PolarCoordinateSettingData::getTitle() const
    {
        return m_title;
    }

    void PolarCoordinateSettingData::setLegend(Style2D_Legend* data)
    {
        m_legend = data;
    }

    Style2D_Legend* PolarCoordinateSettingData::getLegend() const
    {
        return m_legend;
    }

    //void PolarCoordinateSettingData::setDataProperty(Style2D_DataProperty* data)
    //{
    //    m_dataProperty = data;
    //}
    //
    //Style2D_DataProperty* PolarCoordinateSettingData::getDataProperty() const
    //{
    //    return m_dataProperty;
    //}

    QDomElement& PolarCoordinateSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _LineChartCoordinateSettingDataRoot = doc->createElement("PolarCoordinateSettingData");
        QDomAttr idattr = doc->createAttribute("ID");
        idattr.setValue(QString::number(1));
        _LineChartCoordinateSettingDataRoot.setAttributeNode(idattr);

        m_angleAxisDisplay->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);
        m_angleAxisRange->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);
        m_radiusAxisDisplay->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);
        m_radiusAxisRange->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);
        m_grid->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);
        m_title->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);
        m_legend->writeToProjectFile(doc, &_LineChartCoordinateSettingDataRoot, isdiso);

        element->appendChild(_LineChartCoordinateSettingDataRoot);

        return _LineChartCoordinateSettingDataRoot;
    }

    void PolarCoordinateSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        int id = element->attribute("ID").toInt();
        auto _AxisDisplayEle = element->elementsByTagName("Style2D_Axis");
        int displayCount = _AxisDisplayEle.count(); // 值为2
        auto _AxisRangeEle = element->elementsByTagName("Style2D_AxisRange");
        int rangeCount = _AxisRangeEle.count(); // 值为2
        auto _gridEle = element->elementsByTagName("Style2D_GridLine");
        auto _titleEle = element->elementsByTagName("Style2D_Title");
        auto _legendEle = element->elementsByTagName("Style2D_Legend");

        m_angleAxisDisplay->readFromProjectFile(&_AxisDisplayEle.at(0).toElement(), isdiso);
        m_angleAxisRange->readFromProjectFile(&_AxisRangeEle.at(0).toElement(), isdiso);
        m_radiusAxisDisplay->readFromProjectFile(&_AxisDisplayEle.at(1).toElement().toElement(), isdiso);
        m_radiusAxisRange->readFromProjectFile(&_AxisRangeEle.at(1).toElement(), isdiso);
        m_grid->readFromProjectFile(&_gridEle.at(0).toElement(), isdiso);
        m_title->readFromProjectFile(&_titleEle.at(0).toElement(), isdiso);
        m_legend->readFromProjectFile(&_legendEle.at(0).toElement(), isdiso);
    }



}
